﻿using NDI;
using Services4KouDai;
using Services4KouDai.Encrypt;

namespace ServiceTest
{
    /// <summary>
    /// 模仿app类中的初始化
    /// </summary>
    public class App
    {
        #region Sigleton

        private static App _instance;

        private App()
        {

        }

        public static App Current
        {
            get
            {
                if (_instance == null)
                {
                    _instance = new App();
                }
                return _instance;
            }

        }

        #endregion
       

        private Container _container;

        public Container AppContainer
        {
            get { return _container; }
        }

        public void Init()
        {
            var builder = new ContainerBuilder();

            InitiCommonHeader();

            InitPlatformSpecific(builder);

            InitService(builder);

            _container = builder.Build();
        }

        private void InitService(ContainerBuilder builder)
        {
            ServiceModule.Init(builder);
        }

        private void InitPlatformSpecific(ContainerBuilder builder)
        {
            builder.Register<IEncrypt>(c => new PhoneEncryptor()).ReuseWithin(ReuseScope.Container).OwnedBy(Owner.Container);
        }


        private void InitiCommonHeader()
        {
            ServiceConstants.CommonHeaders.Add("apiv", "6");
            ServiceConstants.CommonHeaders.Add("brand", "Microsoft");
            ServiceConstants.CommonHeaders.Add("mid", "XDeviceEmulator");
            ServiceConstants.CommonHeaders.Add("w", "480");
            ServiceConstants.CommonHeaders.Add("h", "800");
            ServiceConstants.CommonHeaders.Add("imei", "UExs93ToaM1CQqxLiC2+SC19E24=");
            ServiceConstants.CommonHeaders.Add("mac", "UExs93ToaM1CQqxLiC2+SC19E24=");
            ServiceConstants.CommonHeaders.Add("udid", "UExs93ToaM1CQqxLiC2+SC19E24=");
            ServiceConstants.CommonHeaders.Add("platform", "wp7");
            ServiceConstants.CommonHeaders.Add("os", "8.0.9903.0");
            ServiceConstants.CommonHeaders.Add("version", "2.0.0");
            ServiceConstants.CommonHeaders.Add("channel", "1000X");
            ServiceConstants.CommonHeaders.Add("build", "20121027");
        }
    }
}
